package com.doeis.common.utils;

import java.util.Random;


public class PasswordUtils {
	private final static int PASSWORD_LENGTH = 6;
	
	/**
	 * 随机生成岗位密码
	 * 
	 * @return
	 */
	public static String randomPassword(){
		return randomString(PASSWORD_LENGTH);
	}
	
	/**
	 * 生成登录名及salt生成用户密码
	 * @param login
	 * @param salt
	 * @return
	 */
	public static String encrypt(String password, String salt){
		return Encrypt.sha_1(password+salt);
	}
	
	/**
	 * 生成用户的加密调味剂
	 * @param login
	 * @return
	 */
	public static String getPasswordSalt(String login){
		return Encrypt.sha_1(login+System.currentTimeMillis());
	}

	/**
	 * 生成网机注册时的激活码
	 * @param length
	 * @return
	 */
	private static String randomString(int length) {

		StringBuffer buffer = new StringBuffer("0123456789abcdefghijklmnopqrstuvwxyz");
		StringBuffer sb = new StringBuffer();
		Random r = new Random();
		int range = buffer.length();
		for (int i = 0; i < length; i++) {
			sb.append(buffer.charAt(r.nextInt(range)));
		}
		return sb.toString();
	}
	
	public static void main(String[] args) {
		String p = "x8ld2h";
		String s = "71345aad26bf6dfefdee41dbc647370cbc0876b4";
		System.out.println(encrypt(p,s));
	}
}
